package com.huayi.website.controller;

import com.huayi.website.entity.EnumCompany;
import com.huayi.website.entity.EnumLanguage;
import com.huayi.website.entity.EnumPages;
import com.huayi.website.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class ProfileController {
    @Autowired
    private BannerService bannerService;
    @Autowired
    private ProductService productService;
    @Autowired
    private PhotoService photoService;
    @Autowired
    private PageContentService pageContentService;
    @Autowired
    private PagesService pagesService;

    /**
     * 云商
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/{language}/yunshang")
    public String yunshang(HttpServletRequest request, @PathVariable String language, Model model){
        System.out.println(language);
        EnumLanguage languageEnum = EnumLanguage.getEnum(language);
        model.addAttribute("language",language);
        model.addAttribute("company","yunshang");

        EnumCompany company = EnumCompany.YunShange;

        var banners = bannerService.getAllList(EnumPages.About_Yun);
        model.addAttribute("banners",banners);

        var products = productService.getAllList(1,10,"",null,company.getIndex());
        model.addAttribute("products",products.getList());

        //生产环境
        var photos1 = photoService.getPhotoAttachmentListById(1);
        model.addAttribute("photos1",photos1);
        //企业荣耀
        var photos2 = photoService.getPhotoAttachmentListById(2);
        model.addAttribute("photos2",photos2);

        var pageContent = pageContentService.getByPageIdAndLanguage(EnumPages.About_Yun.getIndex(), languageEnum);
        model.addAttribute("pc",pageContent);
        model.addAttribute("menuId","profile");
        //获取页面信息，设置title
        var page = pagesService.getById(EnumPages.About_Yun);
        if (languageEnum == EnumLanguage.CHINESE) {
            model.addAttribute("layout", "layout_zh");
            model.addAttribute("pageTitle", page.getTitleCn());
        }
        else {
            model.addAttribute("pageTitle", page.getTitleEn());
            model.addAttribute("layout", "layout");
        }
        return "profile";
    }

    /**
     * 锦麟
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/{language}/jinlin")
    public String jinlin(HttpServletRequest request, @PathVariable String language, Model model){
        System.out.println(language);
        EnumLanguage languageEnum = EnumLanguage.getEnum(language);
        model.addAttribute("language",language);
        model.addAttribute("company","jinlin");

        EnumCompany company = EnumCompany.JinLin;
        var banners = bannerService.getAllList(EnumPages.About_JinLin);
        model.addAttribute("banners",banners);
        var products = productService.getAllList(1,10,"",null,company.getIndex());
        model.addAttribute("products",products.getList());

        var pageContent = pageContentService.getByPageIdAndLanguage(EnumPages.About_JinLin.getIndex(),languageEnum);
        model.addAttribute("pc",pageContent);
        model.addAttribute("menuId","profile");

        //生产环境
        var photos1 = photoService.getPhotoAttachmentListById(3);
        model.addAttribute("photos1",photos1);
        //企业荣耀
        var photos2 = photoService.getPhotoAttachmentListById(4);
        model.addAttribute("photos2",photos2);

        //获取页面信息，设置title
        var page = pagesService.getById(EnumPages.About_JinLin);
        if (languageEnum == EnumLanguage.CHINESE) {
            model.addAttribute("layout", "layout_zh");
            model.addAttribute("pageTitle", page.getTitleCn());
        }
        else {
            model.addAttribute("pageTitle", page.getTitleEn());
            model.addAttribute("layout", "layout");
        }
        return "profile";
    }
}
